<?php

    require "../public/functions.php";
    $link = mysqli_connect("localhost","root","") or die("数据连接失败");
    mysqli_set_charset($link,"utf8");
    mysqli_select_db($link,"bbs");
    switch($_GET['a']){
        case 'del':
//            $path = $_GET['path'];
//            var_dump($path);

            $id = $_GET['id'];
            $sql = "delete from type where id={$id}";
            $result = mysqli_query($link,$sql);

            if($result && mysqli_affected_rows($link)>0){
                echo "<script>alert('删除成功！');window.location.href='./main_menu.php';</script>";
                die;
            }else{
                echo "<script>alert('删除失败！');window.location.href='./main_menu.php';</script>";
                die;
            }

            break;

        case 'edit':
            $id = $_POST['id'];
            $logo = $_FILES['logo'];
            $typename = $_POST['typename'];
            $status = $_POST['status'];
            $path="../../public/home/img/";
            $maxsize=0;
            $fileType=array("image/jpeg","image/gif","image/png");
            $res=upload($path,$fileType,$maxSize=0,$logo);
//			var_dump($res);
            $newName = $res['newName'];

            $line = "x_";
            $maxw =55;
            $maxh =55;
            getImages($path,$newName,$line,$maxw,$maxh);

//    $path = rtrim($path,'/').'/';
            $newlogo = $line.$newName;
            if( !empty($typename)){

//                $path="../../public/home/img/";
                //            var_dump($id);
                //            var_dump($logo);
                //            var_dump($typename);
                //            var_dump($newpath);
                //            var_dump($name);
                $sql = "update type set name='{$typename}',status='{$status}',blogo='{$newlogo}' where id={$id}";
                mysqli_query($link,$sql);
                if(mysqli_affected_rows($link)>0){
                    echo "<script>alert('修改成功！');window.location.href='./main_menu.php';</script>";
                    die;
                }else{
                    echo "<script>alert('修改失败！');window.location.href='./main_menu.php';</script>";
                    die;
                }
            }else{
                echo "<script>alert('板块名字不能为空！');window.location.href='./main_menu.php';</script>";
            }

            break;
    }
    mysqli_close($link);